package com.action.basic;

import java.util.List;

import com.action.common.WEB;
import com.action.setting.JobMenuAction;
import com.opensymphony.xwork2.ActionSupport;
import com.pojo.basic.ModuleUsers;
import com.service.basic.IModuleUsersService;
import com.util.ActionLog;

public class PriviledgeAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String  id;
	private Integer  moduleId;
	private IModuleUsersService moduleUsersService;
	//get set
	public String getId() {
		return id;
	}

	public void setModuleUsersService(IModuleUsersService moduleUsersService) {
		this.moduleUsersService = moduleUsersService;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public Integer getModuleId() {
		return moduleId;
	}

	public void setModuleId(Integer moduleId) {
		this.moduleId = moduleId;
	}
	//action 
	public String initPriviledge(){
		ActionLog.info(JobMenuAction.class,"["+WEB.getClassName(this.getClass())+"]:【驗證當前登錄員工是否擁有該模組的權限】");
		List<ModuleUsers> moduleUsers = moduleUsersService.findModuleUsersByModuleIdAndUsers(moduleId, WEB.getSession().get("username").toString().toUpperCase());
		if(moduleUsers == null || moduleUsers.size()==0){
			return "unpriviledge";
		}
		if(this.getId().equals("PA")){
			return "PA";
		}
		if(this.getId().equals("INV")){
			return "INV";
		}
		if(this.getId().equals("ACC")){
			return "ACC";
		}
		if(this.getId().equals("MON")){
			return "MON";
		}
		if(this.getId().equals("BasicData")){
			return "BasicData";
		}
		if(this.getId().equals("Setting")){
			return "Setting";
		}
		return SUCCESS;
	}
}
